package com.tuananh.radnom.model;

import java.util.ArrayList;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.tuananh.radnom.model.netservice.NetService;

/**
 * 
 * @author SilentSkyTA Version 0.0.1-SNAPSHOT A NetInterface object represents
 *         an Network Inteface Card
 */
@XmlRootElement(name = "interface")
public class NetInterface extends NetElement {
	String ipAddress;
	String macAddress;
	NetNode netNode;
	ArrayList<NetService> netServices;
	
	@XmlElement(name="service")
	public ArrayList<NetService> getNetServices() {
		if (netServices == null)
			netServices = new ArrayList<NetService>();
		return netServices;
	}

	public void setNetServices(ArrayList<NetService> netServices) {
		this.netServices = netServices;
	}
	@XmlElement(required = false)
	public NetNode getNetNode() {
		return netNode;
	}

	public void setNetNode(NetNode netNode) {
		this.netNode = netNode;
	}

	public String getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}
	@XmlAttribute(name="mac")
	public String getMacAddress() {
		return macAddress;
	}

	public void setMacAddress(String macAddress) {
		this.macAddress = macAddress;
	}

	public boolean validate(Object ne) {
		// TODO Auto-generated method stub
		return true;
	}

	public boolean assign(Object obj) {
		// TODO Auto-generated method stub
		super.assign(obj);
		try {
			NetInterface netInt = (NetInterface) obj;
			this.ipAddress = netInt.getIpAddress();
			this.macAddress = netInt.getMacAddress();
			this.netServices = (ArrayList<NetService>) netInt.getNetServices().clone();
		} catch (Exception e) {
			return false;
		}
		return true;
	}
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		if (obj instanceof NetInterface){
			if (((NetInterface)obj).getName().equals(this.getName()))
				return true;
		}
		return false;
	}
}
